package com.mission.schedule.CommonViewController;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.mission.schedule.R;
import com.mission.schedule.adapter.utils.CommonAdapter;
import com.mission.schedule.adapter.utils.ViewHolder;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CalenderNoteBean;
import com.mission.schedule.bean.WBA_FindFunctionMy;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.entity.CLCategoryTable;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.entity.ScheduleTable;
import com.mission.schedule.my160920.bean.LyNewNumBean;
import com.mission.schedule.utils.CharacterUtil;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.UriUtils;
import com.mission.schedule.utils.Utils;
import com.mission.schedule.widget.SwipeLinearLayout;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class CommonSearchTagAdapter extends CommonAdapter<Map<String, String>> {

    private Context context;
    private List<Map<String, String>> mList;
    private Handler handler;
    String localpath = "0";// 本地存储的背景
    String outweekfag = "0";// 判断一周后展示布局是否显示
    int width = 0;
    SharedPrefUtil sharedPrefUtil = null;
    List<Map<String, String>> outweekList = null;

    private String S4 = "GT-I9500",userid="";//android.os.Build.MODEL
    /**
     * 消息状态
     */
    private List<LyNewNumBean.ListBean> listBeanList = new ArrayList<>();

    public CommonSearchTagAdapter(Context context, List<Map<String, String>> lDatas,
                                  int layoutItemID, Handler handler, int width) {
        super(context, lDatas, layoutItemID);
        this.context = context;
        this.mList = lDatas;
        this.handler = handler;
        this.width = width;
        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        outweekList = new ArrayList<Map<String, String>>();
        userid = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "");
    }

    private void setOnclick(int positions, Map<String, String> map, int what, int type) {
        Message message = Message.obtain();
        message.arg1 = positions;
        message.arg2 = type;
        message.obj = map;
        message.what = what;
        handler.sendMessage(message);
    }

    List<SwipeLinearLayout> swipeLinearLayouts = new ArrayList<>();

    @SuppressLint("NewApi")
    @Override
    public void getViewItem(ViewHolder holder, final Map<String, String> mMap,
                            final int position) {
        final SwipeLinearLayout swipeLayout = holder.getView(R.id.sch_sl);
        //添加侧滑
        swipeLinearLayouts.add(swipeLayout);
        swipeLayout.setOnSwipeListener(new SwipeLinearLayout.OnSwipeListener() {
            @Override
            public void onDirectionJudged(SwipeLinearLayout thisSll, boolean isHorizontal) {
                if (false == isHorizontal) {
                    for (SwipeLinearLayout sll : swipeLinearLayouts) {
                        if (null == sll) {
                            continue;
                        }
                        sll.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                    }
                } else {
                    for (SwipeLinearLayout sll : swipeLinearLayouts) {
                        if (null == sll) {
                            continue;
                        }
                        if (!sll.equals(thisSll)) {
                            //划开一个sll， 其他收缩
                            sll.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                        }
                    }
                }
            }
        });
        LinearLayout top_ll = holder.getView(R.id.top_ll);
        LinearLayout timeall_ll = holder.getView(R.id.timeall_ll); // 标题栏，包含今天，日期，农历等
        TextView timeall_tv_month = holder.getView(R.id.timeall_tv_month); // 日期
        // 如：08-31
        TextView timeall_tv_week = holder.getView(R.id.timeall_tv_week); // 周几
        // 如：周二
        TextView timeall_tv_daycount = holder.getView(R.id.timeall_tv_daycount); // 今天，明天，几天后
        final LinearLayout timeall_rela_right = holder.getView(R.id.timeall_rela_right); // 下面整体布局
        final TextView timeall_tv_time = holder.getView(R.id.timeall_tv_time); // 时间
        // 如：全天或08：00
        TextView timeall_tv_shun = holder.getView(R.id.timeall_tv_shun); // 顺延
        // 如：顺
        TextView timeall_tv_lastday = holder.getView(R.id.timeall_tv_lastday); // 多少小时后，多少天后
        final TextView timeall_tv_content = holder.getView(R.id.timeall_tv_content); // 日程内容
        // TextView timeall_tv_has = holder.getView(R.id.timeall_tv_has); //
        // 标题栏天后
        TextView personstate_tv = holder.getView(R.id.personstate_tv);// 公开状态
        TextView tv_delete = holder.getView(R.id.tv_delete);// 删除
        LinearLayout tv_more = holder.getView(R.id.ll_more);// 更多
        LinearLayout more_ll = holder.getView(R.id.delete_ll);// 侧滑
        ImageView guoqi_img = holder.getView(R.id.guoqi_img);// 过期未结束图标，在今天中才显示
        TextView comename_tv = holder.getView(R.id.comename_tv);// 来自谁的日程
        LinearLayout datebackground_ll = holder.getView(R.id.datebackground_ll);// 今天和日期的背景
        final CheckBox select_cb = holder.getView(R.id.select_cb);
        TextView timeall_tv_nongli = holder.getView(R.id.timeall_tv_nongli);// 农历日期显示
        final TextView bottom_month = holder.getView(R.id.bottom_month);
        final TextView bottom_week = holder.getView(R.id.bottom_week);
        LinearLayout select_cb_ll = holder.getView(R.id.select_cb_ll);
        final LinearLayout outweek_ll = holder.getView(R.id.outweek_ll);// 一周以后布局
        final TextView outweekcount_tv = holder.getView(R.id.outweekcount_tv);
        LinearLayout newcome_ll = holder.getView(R.id.newcome_ll);
        TextView newcome_tv = holder.getView(R.id.newcome_tv);
        TextView timeall_after = holder.getView(R.id.timeall_after);// 标题栏几天后
        TextView xcx_tv = holder.getView(R.id.xcx_tv);

        ImageView important_icon = holder.getView(R.id.important_icon);
//        if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
//                && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
//            if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
//                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//                        Utils.dipTopx(context, 90), LayoutParams.MATCH_PARENT);
//                more_ll.setLayoutParams(params);
//                tv_more.setVisibility(View.GONE);
//            } else {
//                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//                        Utils.dipTopx(context, 180), LayoutParams.MATCH_PARENT);
//                more_ll.setLayoutParams(params);
//                tv_more.setVisibility(View.VISIBLE);
//            }
//        } else {
//            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//                    Utils.dipTopx(context, 90), LayoutParams.MATCH_PARENT);
//            more_ll.setLayoutParams(params);
//            tv_more.setVisibility(View.GONE);
//        }

        //new_img 好友日程状态
        ImageView new_img = holder.getView(R.id.new_img);

        timeall_rela_right.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击详情菜单
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                setOnclick(position, mMap, 0, 0);
            }
        });
        timeall_rela_right.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                setOnclick(position, mMap, 7, 0);
                return true;
            }
        });
        timeall_ll.setOnClickListener(new OnClickListener() {
            // 点击日历进入
            @Override
            public void onClick(View v) {
                setOnclick(position, mMap, 4, 0);
            }
        });
        tv_delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                // 右滑删除
                setOnclick(position, mMap, 3, 0);
            }
        });
        tv_more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swipeLayout.scrollAuto(SwipeLinearLayout.DIRECTION_SHRINK);
                // 右滑删除
                setOnclick(position, mMap, 7, 0);
            }
        });
        select_cb_ll.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 选中表示结束
                if (select_cb.isChecked() == true) {
                    setOnclick(position, mMap, 2, 0);
                } else {
                    setOnclick(position, mMap, 2, 1);
                }
            }
        });

        select_cb.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 选中表示结束
                if (select_cb.isChecked() == true) {
                    setOnclick(position, mMap, 2, 0);
                } else {
                    setOnclick(position, mMap, 2, 1);
                }
            }
        });
        outweek_ll.setOnClickListener(new OnClickListener() {
            // 点击一周后
            @Override
            public void onClick(View v) {
                setOnclick(position, mMap, 5, 0);
                sharedPrefUtil.putString(context, ShareFile.USERFILE,
                        ShareFile.OUTWEEKFAG, "1");
                outweekfag = "1";
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
            }
        });
        String displayAlarm = mMap.get(ScheduleTable.schDisplayTime);
        String postpone = mMap.get(ScheduleTable.schIsPostpone);
        String alarmClockTime = mMap.get(ScheduleTable.schTime);
        String isEnd = mMap.get(ScheduleTable.schIsEnd);
        int beforTime = Integer.parseInt(mMap.get(ScheduleTable.schBeforeTime));
        String important = mMap.get(ScheduleTable.schIsImportant);

        String today, tomorrow, inweek;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        today = DateUtil.formatDateTime(calendar.getTime());
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.get(Calendar.DAY_OF_MONTH) + 1);
        tomorrow = DateUtil.formatDateTime(calendar.getTime());
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.get(Calendar.DAY_OF_MONTH) + 7);
        inweek = DateUtil.formatDateTime(calendar.getTime());
        if (position == 0) {
            try {
                outweekList = App.getDBcApplication().queryAllSchData(5, 0, 0);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (mList != null && mList.size() > 0) {
                int untaskcount = 0;
                int todaytaskcount = 0;
                int tomorrowtaskcount = 0;
                int inweektaskcount = 0;
                for (int i = 0; i < mList.size(); i++) {
                    if (mList.get(i).get(ScheduleTable.schDate)
                            .equals(today.substring(0, 10))) {
                        if ("0".equals(mList.get(i).get(
                                ScheduleTable.schDisplayTime))
                                && "1".equals(mList.get(i).get(
                                ScheduleTable.schIsPostpone))) {
                            untaskcount = untaskcount + 1;
                        } else {
                            todaytaskcount = todaytaskcount + 1;
                        }
                    } else if (mList.get(i).get(ScheduleTable.schDate)
                            .equals(tomorrow.substring(0, 10))) {
                        tomorrowtaskcount = tomorrowtaskcount + 1;
                    } else if (DateUtil.parseDate(inweek.substring(0, 10))
                            .getTime() >= DateUtil.parseDate(
                            mList.get(i).get(ScheduleTable.schDate)).getTime()
                            && DateUtil.parseDate(
                            mList.get(i).get(ScheduleTable.schDate))
                            .getTime() > DateUtil.parseDate(tomorrow)
                            .getTime()) {
                        inweektaskcount = inweektaskcount + 1;
                    }
                }
            }
        }
        String key = mMap.get(ScheduleTable.schDate);
        String timeKey = mMap.get(ScheduleTable.schTime);

        Date dateStr = DateUtil.parseDateTime(key + " " + timeKey);
        String[] ymd = key.split("-");

        String clockTime = "";
        String point = "",point2 = "";
        String sequence = "";
        int shunBackKuang = 0;
        String colorState = "" + context.getResources().getColor(R.color.mingtian_color);
        String beforeStr = "";

        if (beforTime == 0) {
            beforeStr = "0";
        } else if (beforTime == 5) {
            beforeStr = "-5";
        } else if (beforTime == 15) {
            beforeStr = "-15";
        } else if (beforTime == 30) {
            beforeStr = "-30";
        } else if (beforTime == 60) {
            beforeStr = "-1h";
        } else if (beforTime == 120) {
            beforeStr = "-2h";
        } else if (beforTime == 1440) {
            beforeStr = "-1d";
        } else if (beforTime == 2 * 1440) {
            beforeStr = "-2d";
        } else if (beforTime == 3 * 1440) {
            beforeStr = "-3d";
        } else if (beforTime == 5 * 1440) {
            beforeStr = "-5d";
        } else if (beforTime == 7 * 1440) {
            beforeStr = "-1w";
        } else if (beforTime == 15 * 1440) {
            beforeStr = "-3w";
        } else {
            beforeStr = "0";
        }

        if ("1".equals(isEnd)) {
            colorState = "#7F7F7F";// "#9f9f9f";
            shunBackKuang = R.drawable.tv_kuang_before;
        } else {
            if (today.substring(0, 10).equals(key)) {
                colorState = ""
                        + context.getResources().getColor(
                        R.color.mingtian_color);
            } else if (tomorrow.substring(0, 10).equals(key)) {
                colorState = ""
                        + context.getResources().getColor(
                        R.color.mingtian_color);
            } else {
                colorState = ""
                        + context.getResources().getColor(
                        R.color.mingtian_color);
            }

            shunBackKuang = R.drawable.tv_kuang_aftertime;
        }
        if (beforeStr.equals("0")) {
            clockTime = "<font color='" + colorState + "' size='5px'>"
                    + alarmClockTime + "</font>";
        } else {
            clockTime = "<font color='" + colorState + "' size='5px'>"
                    + alarmClockTime + "(" + beforeStr + ")" + "</font>";
        }
        // clockTime = "<font color='" + colorState + "' size='5px'>"
        // + alarmClockTime + "(" + beforeStr + ")" + "</font>";
        // 全天
        point = "<font color='" + colorState + "' size='5px'>"
                + context.getString(R.string.adapter_allday) + "</font>";
        point2 = "<font color='#7F7F7F' size='5px'>"
                + context.getString(R.string.adapter_allday) + "</font>";
        // 顺延
        sequence = "<font color='" + colorState + "'>"
                + context.getString(R.string.adapter_shun) + "</font>";

        timeall_tv_content.setText((mMap.get(ScheduleTable.schContent).length() > 2 &&
                mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                mMap.get(ScheduleTable.schContent));
        if ("1".equals(isEnd)) {
            timeall_tv_content.setTextColor(Color.parseColor(colorState));
            timeall_tv_time.setTextColor(Color.parseColor(colorState));
            bottom_month.setTextColor(Color.parseColor(colorState));
            bottom_week.setTextColor(Color.parseColor(colorState));
            timeall_tv_content.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            timeall_tv_time.setTextColor(context.getResources().getColor(
                    R.color.mingtian_color));
            bottom_month.setTextColor(context.getResources().getColor(
                    R.color.mingtian_color));
            bottom_week.setTextColor(context.getResources().getColor(
                    R.color.mingtian_color));
            timeall_tv_content.setTextColor(Color.BLACK);
            timeall_tv_content.getPaint().setFlags(0 | Paint.ANTI_ALIAS_FLAG);
        }

        String openState = mMap.get(ScheduleTable.schOpenState);
        personstate_tv.setVisibility(View.GONE);
        if (openState.equals("0")) {
            // personstate_tv.setText("私密");
            personstate_tv.setText("");
        } else if (openState.equals("1")) {
            personstate_tv.setText("公开");
        } else {
            // personstate_tv.setText("好友可见");
            personstate_tv.setText("");
        }

        if ("0".equals(mMap.get(ScheduleTable.schColorType))) {
            personstate_tv.setVisibility(View.GONE);
        } else {
            if (!"".equals(mMap.get(ScheduleTable.schColorType))) {
                String tagname = App.getDBcApplication().QueryTagNameData(
                        Integer.parseInt(mMap.get(ScheduleTable.schColorType)))
                        .get(CLCategoryTable.ctgText);
                if ("未分类".equals(tagname)) {
                    personstate_tv.setVisibility(View.GONE);
                } else {
                    personstate_tv.setVisibility(View.VISIBLE);
                }
                personstate_tv.setText(tagname);
            }
        }
        String nongli = "";
        if (mList.size() > 0) {
            if (DateUtil.parseDate(mMap.get(ScheduleTable.schDate)).after(DateUtil.parseDate("2017-12-31"))) {
                nongli = App.getDBcApplication()
                        .queryLunartoSolarList(mMap.get(ScheduleTable.schDate), 0).get("lunarCalendar");
                timeall_tv_nongli.setText(nongli);
            }
        }
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(DateUtil.parseDate(mMap.get(ScheduleTable.schDate)));

        Date dateToday = DateUtil.parseDateTime(DateUtil.formatDateTime(new Date()));
        long betweem = (long) (dateToday.getTime() - dateStr.getTime()) / 1000;
        long day = betweem / (24 * 3600);
        long hour = betweem % (24 * 3600) / 3600;
        long min = betweem % 3600 / 60;
        long afterday = ((long) (DateUtil.parseDate(
                DateUtil.formatDate(new Date())).getTime() - DateUtil
                .parseDate(key).getTime()) / 1000) / (24 * 3600);

        if (position == 0) {
            // 当position=0，判断今天中是否有待办日程，有就隐藏标题栏，隐藏顺和天后，如果今天没有日程，然后判断明天和之后的
            timeall_ll.setVisibility(View.VISIBLE);
            if (today.substring(0, 10).equals(key)) {
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                if ("0".equals(displayAlarm) && "1".equals(postpone)) {
                    guoqi_img.setVisibility(View.GONE);
                    timeall_ll.setVisibility(View.GONE);
                    timeall_tv_shun.setVisibility(View.GONE);
                    timeall_tv_lastday.setVisibility(View.GONE);
                    bottom_month.setVisibility(View.GONE);
                    bottom_week.setVisibility(View.GONE);
                    timeall_tv_time.setText(context
                            .getString(R.string.adapter_untask));
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_normal);
                    timeall_tv_time.setTextColor(context.getResources()
                            .getColor(R.color.gongkai_txt));
                } else {
                    timeall_ll.setVisibility(View.VISIBLE);
                    timeall_tv_month.setVisibility(View.VISIBLE);
                    timeall_tv_week.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setText(nongli);
                    bottom_month.setVisibility(View.GONE);
                    bottom_week.setVisibility(View.GONE);
                    // timeall_tv_has.setVisibility(View.GONE);
                    timeall_tv_daycount.setText(context
                            .getString(R.string.adapter_today));
                    datebackground_ll
                            .setBackgroundResource(R.drawable.bg_todaytextview);

                    timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
                    timeall_tv_week.setText(CharacterUtil.getWeekOfDate(
                            context, DateUtil.parseDate(key)));
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_bold);
                    if (!"".equals(localpath)) {
                        if ("0".equals(localpath)) {
                            timeall_tv_week.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                            timeall_tv_nongli.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                        } else {
                            timeall_tv_week.setTextColor(Color.WHITE);
                            timeall_tv_nongli.setTextColor(Color.WHITE);
                        }
                    } else {
                        timeall_tv_week.setTextColor(context.getResources()
                                .getColor(R.color.white));
                        timeall_tv_nongli.setTextColor(context.getResources()
                                .getColor(R.color.white));
                    }
                    if (Math.abs(hour) >= 1) {
                        timeall_tv_lastday.setText(Math.abs(hour) + "小时后");
                    } else if (DateUtil.parseDateTimeHm(timeKey).getTime() > DateUtil
                            .parseDateTimeHm(
                                    DateUtil.formatDateTimeHm(new Date()))
                            .getTime()) {
                        if (Math.abs(min) == 0) {
                            timeall_tv_lastday.setText("");
                        } else {
                            timeall_tv_lastday.setText(Math.abs(min) + "分钟后");
                        }
                    }
                    if ("0".equals(displayAlarm)) {
                        guoqi_img.setVisibility(View.GONE);
                        timeall_tv_lastday.setVisibility(View.GONE);
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_lastday.setVisibility(View.GONE);
                            timeall_ll.setVisibility(View.GONE);
                            timeall_tv_time.setText(context
                                    .getString(R.string.adapter_untask));
                            timeall_tv_time.setTextAppearance(context,
                                    R.style.text_style_normal);
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setTextColor(context.getResources()
                                    .getColor(R.color.gongkai_txt));
                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(point));
                        }
                    } else {
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                            timeall_tv_shun.setVisibility(View.VISIBLE);
                            timeall_tv_shun
                                    .setBackgroundResource(shunBackKuang);
                            timeall_tv_shun.setText(Html.fromHtml(sequence));
                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                        }
                        Date date1 = DateUtil.parseDateTime((DateUtil
                                .formatDateTime(new Date())));
                        if (dateStr.getTime() < date1.getTime()) {
                            if ("0".equals(displayAlarm)) {
                                if ("1".equals(isEnd)) {
                                    guoqi_img.setVisibility(View.GONE);
                                } else {
                                    guoqi_img.setVisibility(View.VISIBLE);
                                }
                                guoqi_img.setVisibility(View.GONE);
                                timeall_tv_lastday.setVisibility(View.GONE);
                            } else {
                                if ("1".equals(isEnd)) {
                                    guoqi_img.setVisibility(View.GONE);
                                } else {
                                    guoqi_img.setVisibility(View.VISIBLE);
                                }
                                timeall_tv_lastday.setVisibility(View.GONE);
                            }
                        } else {
                            guoqi_img.setVisibility(View.GONE);
                            if ("0".equals(displayAlarm)) {
                                timeall_tv_lastday.setVisibility(View.GONE);
                            } else {
                                timeall_tv_lastday.setVisibility(View.VISIBLE);
                            }
                        }
                    }

                }
            } else if (tomorrow.substring(0, 10).equals(key)) {
                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                guoqi_img.setVisibility(View.GONE);
                timeall_tv_month.setVisibility(View.VISIBLE);
                timeall_tv_week.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setText(nongli);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                timeall_ll.setVisibility(View.VISIBLE);
                // timeall_tv_has.setVisibility(View.GONE);
                timeall_tv_daycount.setText(context
                        .getString(R.string.adapter_tomorrow));
                timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
//                timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                datebackground_ll
                        .setBackgroundResource(R.drawable.bg_tommorowtextview);
                timeall_tv_week.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(key)));
                if (!"".equals(localpath)) {
                    if ("0".equals(localpath)) {
                        timeall_tv_week.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        timeall_tv_nongli.setTextColor(Color
                                .parseColor("#7F7F7F"));
                    } else {
                        timeall_tv_week.setTextColor(Color.WHITE);
                        timeall_tv_nongli.setTextColor(Color.WHITE);
                    }
                } else {
                    timeall_tv_week.setTextColor(context.getResources()
                            .getColor(R.color.white));
                    timeall_tv_nongli.setTextColor(context.getResources()
                            .getColor(R.color.white));
                }
                if (Math.abs(day) >= 1) {
                    timeall_tv_lastday.setText(Math.abs(day) + "天后");
                } else {
                    timeall_tv_lastday.setText(Math.abs(hour) + "小时后");

                }
                if ("0".equals(displayAlarm)) {
                    timeall_tv_lastday.setVisibility(View.VISIBLE);
                    if ("1".equals(postpone)) {
                        timeall_tv_lastday.setVisibility(View.VISIBLE);
                        timeall_ll.setVisibility(View.VISIBLE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    timeall_tv_lastday.setVisibility(View.VISIBLE);
                    if ("1".equals(postpone)) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
            } else {
                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_tv_lastday.setVisibility(View.GONE);
                timeall_after.setVisibility(View.VISIBLE);
                timeall_tv_daycount.setVisibility(View.GONE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                guoqi_img.setVisibility(View.GONE);
                timeall_ll.setVisibility(View.VISIBLE);
                timeall_tv_month.setVisibility(View.VISIBLE);
                timeall_tv_week.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setText(nongli);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);

                timeall_tv_daycount.setText(context
                        .getString(R.string.adapter_outweek));
                timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
//                timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                datebackground_ll
                        .setBackgroundResource(R.drawable.bg_tommorowtextview);
                timeall_tv_week.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(key)));
                if (!"".equals(localpath)) {
                    if ("0".equals(localpath)) {
                        timeall_after.setTextColor(Color.parseColor("#7F7F7F"));
                        timeall_tv_nongli.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        timeall_tv_week.setTextColor(Color
                                .parseColor("#7F7F7F"));
                    } else {
                        timeall_after.setTextColor(Color.parseColor("#7F7F7F"));
                        timeall_tv_nongli.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        timeall_tv_week.setTextColor(Color
                                .parseColor("#7F7F7F"));
//                        timeall_tv_nongli.setTextColor(Color.WHITE);
//                        timeall_after.setTextColor(Color.WHITE);
//                        timeall_tv_week.setTextColor(context.getResources().getColor(R.color.white));
                    }
                } else {
                    timeall_after.setTextColor(Color.parseColor("#7F7F7F"));
                    timeall_tv_nongli.setTextColor(Color
                            .parseColor("#7F7F7F"));
                    timeall_tv_week.setTextColor(Color
                            .parseColor("#7F7F7F"));
//                    timeall_after.setTextColor(Color.WHITE);
//                    timeall_tv_nongli.setTextColor(Color.WHITE);
//                    timeall_tv_week.setTextColor(context.getResources().getColor(R.color.white));
                }
                timeall_after.setText(Math.abs(afterday) + "天后");
                if ("0".equals(displayAlarm)) {
                    if ("1".equals(postpone)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        timeall_ll.setVisibility(View.GONE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    if ("1".equals(postpone)) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
            }
        } else if (mList.get(position).get(ScheduleTable.schDate).equals(mList.get(position - 1).get(ScheduleTable.schDate))) {
            // 判断当前日期是否为今天，如果是今天，就得区分待办和今天日程
            // 如果不为今天，就按找平时日程处理
            if (today.substring(0, 10).equals(mList.get(position).get(ScheduleTable.schDate))) {
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                if ("0".equals(displayAlarm) && "1".equals(postpone)) {// &&
                    guoqi_img.setVisibility(View.GONE);
                    timeall_ll.setVisibility(View.GONE);
                    timeall_tv_lastday.setVisibility(View.GONE);
                    timeall_tv_time.setText(context
                            .getString(R.string.adapter_untask));
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_normal);
                    timeall_tv_shun.setVisibility(View.GONE);
                    // timeall_tv_has.setVisibility(View.GONE);
                    timeall_tv_time.setTextColor(context.getResources()
                            .getColor(R.color.gongkai_txt));
                } else {
                    timeall_ll.setVisibility(View.GONE);
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_bold);
                    timeall_tv_month.setVisibility(View.VISIBLE);
                    timeall_tv_week.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setText(nongli);
                    timeall_tv_daycount.setText(context.getResources()
                            .getString(R.string.adapter_today));
//                    timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                    datebackground_ll
                            .setBackgroundResource(R.drawable.bg_todaytextview);
                    timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
                    timeall_tv_week.setText(CharacterUtil.getWeekOfDate(
                            context, DateUtil.parseDate(key)));
                    if (!"".equals(localpath)) {
                        if ("0".equals(localpath)) {
                            timeall_tv_week.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                            timeall_tv_nongli.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                        } else {
                            timeall_tv_week.setTextColor(Color.WHITE);
                            timeall_tv_nongli.setTextColor(Color.WHITE);
                        }
                    } else {
                        timeall_tv_week.setTextColor(context.getResources()
                                .getColor(R.color.white));
                        timeall_tv_nongli.setTextColor(context.getResources()
                                .getColor(R.color.white));
                    }
                    if (Math.abs(hour) >= 1) {
                        timeall_tv_lastday.setText(Math.abs(hour) + "小时后");
                    } else if (DateUtil.parseDateTimeHm(timeKey).getTime() > DateUtil
                            .parseDateTimeHm(
                                    DateUtil.formatDateTimeHm(new Date()))
                            .getTime()) {
                        if (Math.abs(min) == 0) {
                            timeall_tv_lastday.setText("");
                        } else {
                            timeall_tv_lastday.setText(Math.abs(min) + "分钟后");
                        }
                    } else {
                        if (Math.abs(min) == 0) {
                            timeall_tv_lastday.setText("");
                        } else {
                            timeall_tv_lastday.setText(Math.abs(min) + "分钟前");
                        }
                    }
                    if ("0".equals(displayAlarm)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        guoqi_img.setVisibility(View.GONE);
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_lastday.setVisibility(View.GONE);
                            timeall_ll.setVisibility(View.GONE);
                            timeall_tv_time.setText(context
                                    .getString(R.string.adapter_untask));
                            timeall_tv_time.setTextAppearance(context,
                                    R.style.text_style_normal);
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setTextColor(context.getResources()
                                    .getColor(R.color.gongkai_txt));
                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(point));
                        }
                    } else {
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                            timeall_tv_shun.setVisibility(View.VISIBLE);
                            timeall_tv_shun
                                    .setBackgroundResource(shunBackKuang);
                            timeall_tv_shun.setText(Html.fromHtml(sequence));
                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                        }
                        Date date1 = DateUtil.parseDateTime((DateUtil
                                .formatDateTime(new Date())));
                        if (dateStr.getTime() < date1.getTime()) {
                            if ("1".equals(isEnd)) {
                                guoqi_img.setVisibility(View.GONE);
                            } else {
                                guoqi_img.setVisibility(View.VISIBLE);
                            }
                            timeall_tv_lastday.setVisibility(View.GONE);

                        } else {
                            guoqi_img.setVisibility(View.GONE);
                            timeall_tv_lastday.setVisibility(View.VISIBLE);
                        }
                    }
                }
            } else if (tomorrow.substring(0, 10).equals(mMap.get(ScheduleTable.schDate))) {
                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                guoqi_img.setVisibility(View.GONE);
                timeall_ll.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                if (Math.abs(day) >= 1) {
                    timeall_tv_lastday.setText(Math.abs(day) + "天后");
                } else {
                    timeall_tv_lastday.setText(Math.abs(hour) + "小时后");

                }
                if ("0".equals(displayAlarm)) {
                    timeall_tv_lastday.setVisibility(View.GONE);
                    if ("1".equals(postpone)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        timeall_ll.setVisibility(View.GONE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    timeall_tv_lastday.setVisibility(View.VISIBLE);
                    if ("1".equals(postpone)) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
            } else {

                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_after.setVisibility(View.GONE);
                timeall_tv_lastday.setVisibility(View.GONE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                if (mList.get(position).get(ScheduleTable.schDate).equals(mList.get(position - 1).get(ScheduleTable.schDate))) {
                    timeall_ll.setVisibility(View.GONE);
                    timeall_tv_month.setVisibility(View.GONE);
                    timeall_tv_week.setVisibility(View.GONE);
                    timeall_tv_nongli.setVisibility(View.GONE);
                } else {
                    timeall_ll.setVisibility(View.VISIBLE);
                    timeall_tv_month.setVisibility(View.VISIBLE);
                    timeall_tv_week.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setVisibility(View.VISIBLE);
                }
                timeall_tv_nongli.setText(nongli);
                guoqi_img.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.GONE);
                timeall_tv_nongli.setText(nongli);

                timeall_tv_daycount.setText(context
                        .getString(R.string.adapter_outweek));
                timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
//                timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                datebackground_ll
                        .setBackgroundResource(R.drawable.bg_tommorowtextview);
                timeall_tv_week.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(key)));
                if (!"".equals(localpath)) {
                    if ("0".equals(localpath)) {
                        bottom_week.setTextColor(Color.parseColor("#7F7F7F"));
                    } else {
                        bottom_week.setTextColor(context.getResources()
                                .getColor(R.color.mingtian_color));
                    }
                } else {
                    if ("1".equals(isEnd)) {
                        bottom_week.setTextColor(Color.parseColor("#7F7F7F"));
                    } else {
                        bottom_week.setTextColor(context.getResources()
                                .getColor(R.color.mingtian_color));
                    }
                }
                timeall_after.setText(Math.abs(afterday) + "天后");
                if ("0".equals(displayAlarm)) {
                    if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        timeall_ll.setVisibility(View.GONE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
                // }
            }
        } else {
            if (today.substring(0, 10).toString().equals(key)) {// 今天
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                if ("0".equals(displayAlarm) && "1".equals(postpone)) {
                    timeall_tv_lastday.setVisibility(View.GONE);
                    timeall_ll.setVisibility(View.VISIBLE);
                    timeall_tv_time.setText(context
                            .getString(R.string.adapter_untask));
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_normal);
                    timeall_tv_time.setTextColor(context.getResources()
                            .getColor(R.color.gongkai_txt));
                    timeall_tv_shun.setVisibility(View.GONE);
                } else {
                    timeall_tv_time.setTextAppearance(context,
                            R.style.text_style_bold);
                    timeall_ll.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setText(nongli);
                    timeall_tv_nongli.setVisibility(View.VISIBLE);
                    timeall_tv_daycount.setText(context
                            .getString(R.string.adapter_today));
//                    timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                    datebackground_ll
                            .setBackgroundResource(R.drawable.bg_todaytextview);
                    timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
                    timeall_tv_week.setText(CharacterUtil.getWeekOfDate(
                            context, DateUtil.parseDate(key)));
                    if (!"".equals(localpath)) {
                        if ("0".equals(localpath)) {
                            timeall_tv_week.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                            timeall_tv_nongli.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                        } else {
                            timeall_tv_week.setTextColor(Color.WHITE);
                            timeall_tv_nongli.setTextColor(Color.WHITE);
                        }
                    } else {
                        timeall_tv_week.setTextColor(context.getResources()
                                .getColor(R.color.white));
                        timeall_tv_nongli.setTextColor(context.getResources()
                                .getColor(R.color.white));
                    }
                    if (Math.abs(hour) >= 1) {
                        timeall_tv_lastday.setText(Math.abs(hour) + "小时后");
                    } else if (DateUtil.parseDateTimeHm(timeKey).getTime() > DateUtil
                            .parseDateTimeHm(
                                    DateUtil.formatDateTimeHm(new Date()))
                            .getTime()) {
                        if (Math.abs(min) == 0) {
                            timeall_tv_lastday.setText("");
                        } else {
                            timeall_tv_lastday.setText(Math.abs(min) + "分钟后");
                        }
                    } else {
                        if (Math.abs(min) == 0) {
                            timeall_tv_lastday.setText("");
                        } else {
                            timeall_tv_lastday.setText(Math.abs(min) + "分钟前");
                        }
                    }
                    if ("0".equals(displayAlarm)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_lastday.setVisibility(View.GONE);
                            timeall_ll.setVisibility(View.VISIBLE);
                            timeall_tv_time.setText(context
                                    .getString(R.string.adapter_untask));
                            timeall_tv_time.setTextAppearance(context,
                                    R.style.text_style_normal);
                            timeall_tv_shun.setVisibility(View.GONE);

                            timeall_tv_time.setTextColor(context.getResources()
                                    .getColor(R.color.gongkai_txt));

                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(point));
                        }
                    } else {
                        if ("1".equals(mMap.get(ScheduleTable.schIsPostpone))) {
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                            timeall_tv_shun.setVisibility(View.VISIBLE);
                            timeall_tv_shun
                                    .setBackgroundResource(shunBackKuang);
                            timeall_tv_shun.setText(Html.fromHtml(sequence));
                        } else {
                            timeall_tv_shun.setVisibility(View.GONE);
                            timeall_tv_time.setText(Html.fromHtml(clockTime));
                        }
                        Date date1 = DateUtil.parseDateTime((DateUtil
                                .formatDateTime(new Date())));
                        if (dateStr.getTime() < date1.getTime()) {
                            timeall_tv_lastday.setVisibility(View.GONE);
                            if ("1".equals(isEnd)) {
                                guoqi_img.setVisibility(View.GONE);
                            } else {
                                guoqi_img.setVisibility(View.VISIBLE);
                            }
                        } else {
                            timeall_tv_lastday.setVisibility(View.VISIBLE);
                            guoqi_img.setVisibility(View.GONE);
                        }
                    }
                }
            } else if (tomorrow.substring(0, 10).toString().equals(key)) {// 明天
                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_tv_month.setVisibility(View.VISIBLE);
                timeall_tv_week.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setText(nongli);
                timeall_after.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.VISIBLE);
                outweek_ll.setVisibility(View.GONE);
                outweekcount_tv.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                guoqi_img.setVisibility(View.GONE);
                timeall_ll.setVisibility(View.VISIBLE);
                timeall_tv_nongli.setText(nongli);
                timeall_tv_daycount.setText(context
                        .getString(R.string.adapter_tomorrow));
                timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
//                timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                datebackground_ll
                        .setBackgroundResource(R.drawable.bg_tommorowtextview);
                timeall_tv_week.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(key)));
                if (!"".equals(localpath)) {
                    if ("0".equals(localpath)) {
                        timeall_tv_nongli.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        timeall_tv_week.setTextColor(Color
                                .parseColor("#7F7F7F"));
                    } else {
                        timeall_tv_week.setTextColor(Color.WHITE);
                        timeall_tv_nongli.setTextColor(Color.WHITE);
                    }
                } else {
                    timeall_tv_nongli.setTextColor(context.getResources()
                            .getColor(R.color.white));
                    timeall_tv_week.setTextColor(context.getResources()
                            .getColor(R.color.white));
                }
                if (Math.abs(day) >= 1) {
                    timeall_tv_lastday.setText(Math.abs(day) + "天后");
                } else {
                    timeall_tv_lastday.setText(Math.abs(hour) + "小时后");

                }
                if ("0".equals(displayAlarm)) {
                    timeall_tv_lastday.setVisibility(View.GONE);
                    if ("1".equals(postpone)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        timeall_ll.setVisibility(View.VISIBLE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);

                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    timeall_tv_lastday.setVisibility(View.VISIBLE);
                    if ("1".equals(postpone)) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
            } else {
                timeall_tv_time.setTextAppearance(context,
                        R.style.text_style_bold);
                timeall_tv_lastday.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.GONE);

                if (mList
                        .get(position)
                        .get(ScheduleTable.schDate)
                        .equals(mList.get(position - 1).get(
                                ScheduleTable.schDate))) {
                    timeall_ll.setVisibility(View.GONE);
                    timeall_after.setVisibility(View.GONE);
                    timeall_tv_month.setVisibility(View.GONE);
                    timeall_tv_week.setVisibility(View.GONE);
                    timeall_tv_nongli.setVisibility(View.GONE);
                } else {
                    timeall_ll.setVisibility(View.VISIBLE);
                    timeall_after.setVisibility(View.VISIBLE);
                    timeall_tv_month.setVisibility(View.VISIBLE);
                    timeall_tv_week.setVisibility(View.VISIBLE);
                    timeall_tv_nongli.setVisibility(View.VISIBLE);
                }
                // }
                timeall_tv_nongli.setText(nongli);
                guoqi_img.setVisibility(View.GONE);
                bottom_month.setVisibility(View.GONE);
                bottom_week.setVisibility(View.GONE);
                timeall_tv_daycount.setVisibility(View.GONE);
                timeall_tv_daycount.setText(context
                        .getString(R.string.adapter_outweek));
                timeall_tv_month.setText(ymd[1] + "-" + ymd[2]);
                timeall_tv_daycount.setTextColor(Color.parseColor("#ffffff"));
                datebackground_ll
                        .setBackgroundResource(R.drawable.bg_tommorowtextview);
                timeall_tv_week.setText(CharacterUtil.getWeekOfDate(context,
                        DateUtil.parseDate(key)));
                if (!"".equals(localpath)) {
                    if ("0".equals(localpath)) {
                        timeall_tv_week.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        timeall_tv_nongli.setTextColor(Color
                                .parseColor("#7F7F7F"));
                        if ("1".equals(isEnd)) {
                            bottom_week.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                        } else {
                            bottom_week.setTextColor(context.getResources()
                                    .getColor(R.color.mingtian_color));
                        }
                    } else {
                        timeall_tv_week.setTextColor(Color.WHITE);
                        timeall_tv_nongli.setTextColor(Color.WHITE);
                        if ("1".equals(isEnd)) {
                            bottom_week.setTextColor(Color
                                    .parseColor("#7F7F7F"));
                        } else {
                            bottom_week.setTextColor(context.getResources()
                                    .getColor(R.color.mingtian_color));
                        }
                    }
                } else {
                    timeall_tv_week.setTextColor(Color.WHITE);
                    timeall_tv_nongli.setTextColor(Color.WHITE);
                    if ("1".equals(isEnd)) {
                        bottom_week.setTextColor(Color.parseColor("#7F7F7F"));
                    } else {
                        bottom_week.setTextColor(context.getResources()
                                .getColor(R.color.mingtian_color));
                    }
                }
                if (Math.abs(day) >= 1) {
                    timeall_after.setText(Math.abs(afterday) + "天后");
                } else {
                    timeall_after.setText(Math.abs(hour) + "小时后");

                }
                if ("0".equals(displayAlarm)) {
                    if ("1".equals(postpone)) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        timeall_ll.setVisibility(View.VISIBLE);
                        timeall_tv_time.setText(context
                                .getString(R.string.adapter_untask));
                        timeall_tv_time.setTextAppearance(context,
                                R.style.text_style_normal);
                        timeall_tv_shun.setVisibility(View.GONE);

                        timeall_tv_time.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(point));
                    }
                } else {
                    if ("1".equals(postpone)) {
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                        timeall_tv_shun.setVisibility(View.VISIBLE);
                        timeall_tv_shun.setBackgroundResource(shunBackKuang);
                        timeall_tv_shun.setText(Html.fromHtml(sequence));
                    } else {
                        timeall_tv_shun.setVisibility(View.GONE);
                        timeall_tv_time.setText(Html.fromHtml(clockTime));
                    }
                }
            }
        }

        // }
        // 设置时间距离前一个的距离
        LinearLayout.LayoutParams timeparams = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        if (bottom_month.getVisibility() == View.VISIBLE) {
            timeparams.setMargins(Utils.dipTopx(context, 5), 0, 0, 0);
            timeall_tv_time.setLayoutParams(timeparams);
        }
        // 设置右边删除
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
        // 设置下面布局
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        // 设置距离顶部距离
        LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

        if (timeall_ll.getVisibility() == View.VISIBLE) {

            params2.setMargins(0, Utils.dipTopx(context, 30), 0, 0);
            top_ll.setLayoutParams(params2);

        } else {
            params2.setMargins(0, Utils.dipTopx(context, 3), 0, 0);
            top_ll.setLayoutParams(params2);
        }

//		swipeLayout.setLayoutParams(params1);

        if ("1".equals(isEnd)) {
            select_cb.setChecked(true);
            if ("1".equals(mMap.get(ScheduleTable.schIsImportant))) {
                timeall_rela_right.setBackground(context.getResources().getDrawable(R.drawable.bg_sch_end));
                important_icon.setVisibility(View.VISIBLE);
                important_icon.setBackground(context.getResources().getDrawable(R.mipmap.icon_zhongyao1));
            } else {
                important_icon.setVisibility(View.GONE);
            }
            comename_tv.setTextColor(context.getResources().getColor(
                    R.color.gongkai_txt));
            if (!"0".equals(StringUtils.getIsStringEqulesNull(mMap
                    .get(ScheduleTable.schcRecommendId)))) {
                if (!"".equals(StringUtils.getIsStringEqulesNull(mMap
                        .get(ScheduleTable.schcRecommendName))) &&
                        !StringUtils.getIsStringEqulesNull(mMap.get(ScheduleTable.schcRecommendName)).equals("到期日")) {
                    comename_tv.setVisibility(View.GONE);
                    timeall_tv_lastday.setVisibility(View.GONE);
                    if (mMap.get(ScheduleTable.schSourceDesc).isEmpty()) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        String co = "@" + mMap.get(ScheduleTable.schcRecommendName)+":";
                        String cb = co + ((mMap.get(ScheduleTable.schContent).length() > 2 &&
                                mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                                mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                                mMap.get(ScheduleTable.schContent));
                        SpannableStringBuilder style=new SpannableStringBuilder(cb);
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)),0,co.length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                        comename_tv.setVisibility(View.GONE);
                    } else {
                        String nums = App.getDBcApplication().getCalenderNoteData(mMap.get(ScheduleTable.schSourceDesc));
                        if (!nums.equals("0") && !nums.isEmpty()){
                            nums = "("+nums+")";
                        }else {
                            nums = "";
                        }
                        String co;
                        String schcRecommen = mMap.get(ScheduleTable.schTags);
                        timeall_tv_content.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
                        timeall_tv_content.setText("");
                        String name = (mMap.get(ScheduleTable.schcRecommendId).equals(userid) ? "" : ("@" + mMap.get(ScheduleTable.schcRecommendName)));
                        if (!schcRecommen.isEmpty()) {
                            if (schcRecommen.equals(name)) {
                                schcRecommen = "";
                            } else {
                                schcRecommen = " " + schcRecommen;
                            }
                        }
                        if (mMap.get(ScheduleTable.schcRecommendId).equals(userid)){
                            schcRecommen = "";
                        }
                        co = name + nums + schcRecommen;
                        if (!mMap.get(ScheduleTable.schContent).isEmpty()) {
                            String content1 = mMap.get(ScheduleTable.schContent);
                            if (mMap.get(ScheduleTable.schContent).length() > 25){
                                content1 = mMap.get(ScheduleTable.schContent).substring(0,25);
                            }
                            content1 = (content1.length() > 2 &&
                                    content1.substring(0,2).equals("#%")) ?
                                    content1.substring(2, content1.length()) :
                                    content1;
                            String content = mMap.get(ScheduleTable.schcRecommendId).equals(userid) ? ("#"+content1 +"#") : ("#"+content1);
                            SpannableStringBuilder style = new SpannableStringBuilder(content);
                            style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.blue)), 0, content.length(),
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                            timeall_tv_content.append(style);

                            SpannableStringBuilder style1 = new SpannableStringBuilder(co);
                            style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, co.length(),
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                            timeall_tv_content.append(style1);
                        }
                    }
                    if ("1".equals(isEnd)) {
                        SpannableStringBuilder style = new SpannableStringBuilder(timeall_tv_content.getText().toString());
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.endtextcolor)), 0, timeall_tv_content.getText().toString().length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                    }

                } else {
                    if (!"0".equals(mMap.get(ScheduleTable.schRepeatID))) {
                        String type = App.getDBcApplication().queryRepateType(mMap.get(ScheduleTable.schRepeatID)).get("type");
                        if ("0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                            comename_tv.setVisibility(View.GONE);
                        } else {
                            comename_tv.setVisibility(View.VISIBLE);
                            new_img.setVisibility(View.GONE);
                        }
                        comename_tv.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
                        String repeatDate = mMap.get(ScheduleTable.schRepeatDate).length() > 10 ?
                                mMap.get(ScheduleTable.schRepeatDate).substring(5,10): "";
                        if ("1".equals(type)) {
                            comename_tv.setText("每天重复 "+repeatDate);
                            color = "0";
                        } else if ("2".equals(type)) {
                            comename_tv.setText("每周重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4");
                        } else if ("3".equals(type)) {
                            comename_tv.setText("每月重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3");
                        } else if ("4".equals(type) || "6".equals(type)) {
                            comename_tv.setText("每年重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2");
                        } else {
                            comename_tv.setText("工作日重复 "+repeatDate);
                            color = "0";
                        }
                        if ("1".equals(important)) {
                            important_icon.setVisibility(View.VISIBLE);
                            important_icon.setBackground(context.getResources().getDrawable(R.mipmap.icon_zhongyao1));
                        } else {
                            important_icon.setVisibility(View.GONE);
                        }
                    } else {
                        comename_tv.setVisibility(View.GONE);
                    }
                }
            } else if (!"0".equals(mMap.get(ScheduleTable.schRepeatID))) {
                String type = App.getDBcApplication()
                        .queryRepateType(mMap.get(ScheduleTable.schRepeatID))
                        .get("type");
                if ("0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                    comename_tv.setVisibility(View.GONE);
                } else {
                    comename_tv.setVisibility(View.VISIBLE);
                    new_img.setVisibility(View.GONE);
                }
                String repeatDate = mMap.get(ScheduleTable.schRepeatDate).length() > 10 ?
                        mMap.get(ScheduleTable.schRepeatDate).substring(5,10): "";
                if ("1".equals(type)) {
                    comename_tv.setText("每天重复 "+repeatDate);
                    color = "0";
                } else if ("2".equals(type)) {
                    comename_tv.setText("每周重复 "+repeatDate);
                    color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4");
                } else if ("3".equals(type)) {
                    comename_tv.setText("每月重复 "+repeatDate);
                    color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3");
                } else if ("4".equals(type) || "6".equals(type)) {
                    comename_tv.setText("每年重复 "+repeatDate);
                    color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2");
                } else {
                    comename_tv.setText("工作日重复 "+repeatDate);
                    color = "0";
                }
                if ("1".equals(important)) {
                    important_icon.setVisibility(View.VISIBLE);
                    important_icon.setBackground(context.getResources().getDrawable(R.mipmap.icon_zhongyao1));
                } else {
                    important_icon.setVisibility(View.GONE);
                }
            }

            if ("2".equals(mMap.get(ScheduleTable.schSourceType))){
                timeall_tv_content.setText((mMap.get(ScheduleTable.schContent).length() > 2 &&
                        mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                        mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                        mMap.get(ScheduleTable.schContent));
                List<CalenderNoteBean.PageBean.ItemsBean> list =
                        App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);

                String nums;

                if (list.size() > 0) {
                    if (list.get(0).style == 0) {
                        int endstate = 0;
                        for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                            if (bean.endstate == 1) {
                                endstate++;
                            }
                        }
                        nums = "(" + endstate + "/" + list.size() + ")";
                    } else if (list.get(0).style == 4) {
                        nums = "(" + nums(list.get(0).style,list) + ")";
                    } else {
                        nums = "(" + list.size() + ")";
                    }

                    SpannableStringBuilder style1 = new SpannableStringBuilder(nums);
                    style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, nums.length(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                    timeall_tv_content.append(style1);

                    if ("1".equals(isEnd)) {
                        SpannableStringBuilder style = new SpannableStringBuilder(timeall_tv_content.getText().toString());
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.endtextcolor)), 0, timeall_tv_content.getText().toString().length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                    }
                }
            } else if ("3".equals(mMap.get(ScheduleTable.schSourceType))
                    || "4".equals(mMap.get(ScheduleTable.schSourceType))
                    || "5".equals(mMap.get(ScheduleTable.schSourceType))) {
                timeall_tv_content.setText((mMap.get(ScheduleTable.schContent).length() > 2 &&
                        mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                        mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                        mMap.get(ScheduleTable.schContent));
                if ("3".equals(mMap.get(ScheduleTable.schSourceType))){
                    timeall_tv_content.setTextColor(context.getResources().getColor(R.color.mingtian_color));
                } else {
                    timeall_tv_content.setTextColor(context.getResources().getColor(R.color.blue));
                }
                String nums = App.getDBcApplication().getCalenderNoteData(mMap.get(ScheduleTable.schSourceDesc));
                if (!nums.equals("0") && !nums.isEmpty()) {
                    nums = "(" + nums + ")";
                } else {
                    nums = "";
                }
                SpannableStringBuilder style1 = new SpannableStringBuilder(nums);
                style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, nums.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                timeall_tv_content.append(style1);
                comename_tv.setVisibility(View.VISIBLE);
                comename_tv.setText("@" + mMap.get(ScheduleTable.schcRecommendName));
                comename_tv.setTextColor(context.getResources().getColor(R.color.gongkai_txt));

                if (isEnd.equals("1")) {
                    timeall_tv_content.setTextColor(Color.parseColor(colorState));
                    timeall_tv_time.setTextColor(Color.parseColor(colorState));
                    bottom_month.setTextColor(Color.parseColor(colorState));
                    bottom_week.setTextColor(Color.parseColor(colorState));
                    timeall_tv_content.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                }
            }
        } else {
            if ("1".equals(important)) {
                important_icon.setVisibility(View.VISIBLE);
                important_icon.setBackground(context.getResources().getDrawable(R.mipmap.icon_zhongyao));
            } else {
                important_icon.setVisibility(View.GONE);
            }
            timeall_rela_right.setBackground(context.getResources().getDrawable(R.drawable.bg_sch_normal));
            select_cb.setChecked(false);

            if (!"0".equals(StringUtils.getIsStringEqulesNull(mMap
                    .get(ScheduleTable.schcRecommendId)))) {
                if (!"".equals(StringUtils.getIsStringEqulesNull(mMap.get(ScheduleTable.schcRecommendName))) &&
                        !StringUtils.getIsStringEqulesNull(mMap.get(ScheduleTable.schcRecommendName)).equals("到期日")) {
                    comename_tv.setVisibility(View.GONE);
                    timeall_tv_lastday.setVisibility(View.GONE);
                    if (mMap.get(ScheduleTable.schSourceDesc).isEmpty()) {
                        timeall_tv_lastday.setVisibility(View.GONE);
                        String co = "@" + mMap.get(ScheduleTable.schcRecommendName)+":";
                        String cb = co + ((mMap.get(ScheduleTable.schContent).length() > 2 &&
                                mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                                mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                                mMap.get(ScheduleTable.schContent));
                        SpannableStringBuilder style=new SpannableStringBuilder(cb);
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)),0,co.length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                        comename_tv.setVisibility(View.GONE);
                    } else {
                        String nums = App.getDBcApplication().getCalenderNoteData(mMap.get(ScheduleTable.schSourceDesc));
                        if (!nums.equals("0") && !nums.isEmpty()){
                            nums = "("+nums+")";
                        }else {
                            nums = "";
                        }
                        String co;
                        String schcRecommen = mMap.get(ScheduleTable.schTags);
                        timeall_tv_content.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
                        timeall_tv_content.setText("");
                        String name = (mMap.get(ScheduleTable.schcRecommendId).equals(userid) ? "" : ("@" + mMap.get(ScheduleTable.schcRecommendName)));
                        if (!schcRecommen.isEmpty()) {
                            if (schcRecommen.equals(name)) {
                                schcRecommen = "";
                            } else {
                                schcRecommen = " " + schcRecommen;
                            }
                        }
                        if (mMap.get(ScheduleTable.schcRecommendId).equals(userid)){
                            schcRecommen = "";
                        }
                        co = name + nums + schcRecommen;
                        if (!mMap.get(ScheduleTable.schContent).isEmpty()) {
                            String content1 = mMap.get(ScheduleTable.schContent);
                            if (mMap.get(ScheduleTable.schContent).length() > 25){
                                content1 = mMap.get(ScheduleTable.schContent).substring(0,25);
                            }
                            content1 = (content1.length() > 2 &&
                                    content1.substring(0,2).equals("#%")) ?
                                    content1.substring(2, content1.length()) :
                                    content1;
                            String content = mMap.get(ScheduleTable.schcRecommendId).equals(userid) ? ("#"+content1 +"#") : ("#"+content1);
                            SpannableStringBuilder style = new SpannableStringBuilder(content);
                            style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.blue)), 0, content.length(),
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                            timeall_tv_content.append(style);

                            SpannableStringBuilder style1 = new SpannableStringBuilder(co);
                            style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, co.length(),
                                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色

                            timeall_tv_content.append(style1);
                        }
                    }
                    if ("1".equals(isEnd)) {
                        SpannableStringBuilder style = new SpannableStringBuilder(timeall_tv_content.getText().toString());
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.endtextcolor)), 0, timeall_tv_content.getText().toString().length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                    }

                } else {
                    if (!"0".equals(mMap.get(ScheduleTable.schRepeatID))) {
                        String type = App
                                .getDBcApplication()
                                .queryRepateType(
                                        mMap.get(ScheduleTable.schRepeatID))
                                .get("type");
                        if ("0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                            comename_tv.setVisibility(View.GONE);
                        } else {
                            comename_tv.setVisibility(View.VISIBLE);
                            new_img.setVisibility(View.GONE);
                        }
                        comename_tv.setTextColor(context.getResources()
                                .getColor(R.color.gongkai_txt));
                        String repeatDate = mMap.get(ScheduleTable.schRepeatDate).length() > 10 ?
                                mMap.get(ScheduleTable.schRepeatDate).substring(5,10): "";
                        if ("1".equals(type)) {
                            comename_tv.setText("每天重复 "+repeatDate);
                            color = "0";
                        } else if ("2".equals(type)) {
                            comename_tv.setText("每周重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4");
                        } else if ("3".equals(type)) {
                            comename_tv.setText("每月重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3");
                        } else if ("4".equals(type) || "6".equals(type)) {
                            comename_tv.setText("每年重复 "+repeatDate);
                            color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2");
                        } else {
                            comename_tv.setText("工作日重复 "+repeatDate);
                            color = "0";
                        }
                        setBGcolor(timeall_rela_right, color);
                    } else {
                        comename_tv.setVisibility(View.GONE);
                    }
                }
            } else {
                if (!"0".equals(mMap.get(ScheduleTable.schRepeatID))) {
                    String type = App
                            .getDBcApplication()
                            .queryRepateType(
                                    mMap.get(ScheduleTable.schRepeatID))
                            .get("type");
                    if ("0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                        comename_tv.setVisibility(View.GONE);
                    } else {
                        comename_tv.setVisibility(View.VISIBLE);
                        new_img.setVisibility(View.GONE);
                    }
                    comename_tv.setTextColor(context.getResources().getColor(
                            R.color.gongkai_txt));
                    String repeatDate = mMap.get(ScheduleTable.schRepeatDate).length() > 10 ?
                            mMap.get(ScheduleTable.schRepeatDate).substring(5,10): "";
                    if ("1".equals(type)) {
                        comename_tv.setText("每天重复 "+repeatDate);
                        color = "0";
                    } else if ("2".equals(type)) {
                        comename_tv.setText("每周重复 "+repeatDate);
                        color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.WEEKCOLOR1, "4");
                    } else if ("3".equals(type)) {
                        comename_tv.setText("每月重复 "+repeatDate);
                        color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.MONTHCOLOR2, "3");
                    } else if ("4".equals(type) || "6".equals(type)) {
                        comename_tv.setText("每年重复 "+repeatDate);
                        color = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.YEARCOLOR3, "2");
                    } else {
                        comename_tv.setText("工作日重复 "+repeatDate);
                        color = "0";
                    }
                    if ("1".equals(important)) {
                        important_icon.setVisibility(View.VISIBLE);
                        important_icon.setBackground(context.getResources().getDrawable(R.mipmap.icon_zhongyao));
                    } else {
                        important_icon.setVisibility(View.GONE);
                    }
                    setBGcolor(timeall_rela_right, color);
                } else {
                    comename_tv.setVisibility(View.GONE);
                }
            }

            if ("2".equals(mMap.get(ScheduleTable.schSourceType))){
                timeall_tv_content.setText((mMap.get(ScheduleTable.schContent).length() > 2 &&
                        mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                        mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                        mMap.get(ScheduleTable.schContent));
                List<CalenderNoteBean.PageBean.ItemsBean> list =
                        App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);

                String nums;

                if (list.size() > 0) {
                    if (list.get(0).style == 0) {
                        int endstate = 0;
                        for (CalenderNoteBean.PageBean.ItemsBean bean : list) {
                            if (bean.endstate == 1) {
                                endstate++;
                            }
                        }
                        nums = "(" + endstate + "/" + list.size() + ")";
                    } else if (list.get(0).style == 4) {
                        nums = "(" + nums(list.get(0).style, list) + ")";
                    } else {
                        nums = "(" + list.size() + ")";
                    }

                    SpannableStringBuilder style1 = new SpannableStringBuilder(nums);
                    style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, nums.length(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色
                    Map<String, String> map = App.getDBcApplication().QueryhongFuData(mMap.get(ScheduleTable.schRepeatID));
                    if (map != null) {
                        if (map.get(CLRepeatTable.repContent).length() > 2 && map.get(CLRepeatTable.repContent).substring(0, 2).equals("#%")) {
                            List<CalenderNoteBean.PageBean.ItemsBean> list1 =
                                    App.getDBcApplication().getCalenderNoteDetailData(userid, map.get(CLRepeatTable.repSourceDesc), false);
                            if (list1.size() >= 1 && UriUtils.isUrl(list1.get(0).contents)) {
                                xcx_tv.setVisibility(View.VISIBLE);
                            } else {
                                timeall_tv_content.append(style1);
                            }
                        } else {
                            timeall_tv_content.append(style1);
                        }
                    } else if (mMap.get(ScheduleTable.schContent).length() > 2 && mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) {
                        List<CalenderNoteBean.PageBean.ItemsBean> list1 =
                                App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);
                        if (list1.size() >= 1 && UriUtils.isUrl(list1.get(0).contents)) {
                            xcx_tv.setVisibility(View.VISIBLE);
                        } else {
                            timeall_tv_content.append(style1);
                        }
                    }  else {
                        timeall_tv_content.append(style1);
                    }

                    if ("1".equals(isEnd)) {
                        SpannableStringBuilder style = new SpannableStringBuilder(timeall_tv_content.getText().toString());
                        style.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.endtextcolor)), 0, timeall_tv_content.getText().toString().length(),
                                Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
                        timeall_tv_content.setText(style);
                    }
                }
            } else if ("3".equals(mMap.get(ScheduleTable.schSourceType))
                    || "4".equals(mMap.get(ScheduleTable.schSourceType))
                    || "5".equals(mMap.get(ScheduleTable.schSourceType))) {
                timeall_tv_content.setText((mMap.get(ScheduleTable.schContent).length() > 2 &&
                        mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                        mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                        mMap.get(ScheduleTable.schContent));
                if ("3".equals(mMap.get(ScheduleTable.schSourceType))){
                    timeall_tv_content.setTextColor(context.getResources().getColor(R.color.mingtian_color));
                } else {
                    timeall_tv_content.setTextColor(context.getResources().getColor(R.color.blue));
                }
                String nums = App.getDBcApplication().getCalenderNoteData(mMap.get(ScheduleTable.schSourceDesc));
                if (!nums.equals("0") && !nums.isEmpty()) {
                    nums = "(" + nums + ")";
                } else {
                    nums = "";
                }
                SpannableStringBuilder style1 = new SpannableStringBuilder(nums);
                style1.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.gongkai_txt)), 0, nums.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //设置指定位置文字的颜色
                timeall_tv_content.append(style1);
                comename_tv.setVisibility(View.VISIBLE);
                comename_tv.setText("@" + mMap.get(ScheduleTable.schcRecommendName));
                comename_tv.setTextColor(context.getResources().getColor(R.color.gongkai_txt));

                if (isEnd.equals("1")) {
                    timeall_tv_content.setTextColor(Color.parseColor(colorState));
                    timeall_tv_time.setTextColor(Color.parseColor(colorState));
                    bottom_month.setTextColor(Color.parseColor(colorState));
                    bottom_week.setTextColor(Color.parseColor(colorState));
                    timeall_tv_content.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                }
            }
        }

        if (Integer.valueOf(mList.get(position).get(ScheduleTable.schpisEnd)) == 1) {
            timeall_tv_content.setTextColor(Color.parseColor("#7F7F7F"));
            timeall_tv_time.setTextColor(Color.parseColor("#7F7F7F"));
            bottom_month.setTextColor(Color.parseColor("#7F7F7F"));
            bottom_week.setTextColor(Color.parseColor("#7F7F7F"));
            select_cb.setChecked(true);
            timeall_rela_right.setBackground(context.getResources().getDrawable(R.drawable.bg_sch_end));
            timeall_tv_content.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        }

        if (Integer.valueOf(mMap.get(ScheduleTable.schcRecommendId)) == -2) {
            comename_tv.setVisibility(View.VISIBLE);
            comename_tv.setText("来自网页输入");
            comename_tv.setTextColor(Color.parseColor("#aaaaaa"));
        }
        xcx_tv.setVisibility(View.GONE);
        if (!"0".equals(mMap.get(ScheduleTable.schRepeatID))) {
            Map<String, String> map = App.getDBcApplication().QueryhongFuData(mMap.get(ScheduleTable.schRepeatID));
            if (map != null) {
                WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(map.get(CLRepeatTable.remark2));
                if (!bean.url.isEmpty()) {
                    xcx_tv.setVisibility(View.VISIBLE);
                } else if (map.get(CLRepeatTable.repContent).length() > 2 && map.get(CLRepeatTable.repContent).substring(0,2).equals("#%")) {
                    List<CalenderNoteBean.PageBean.ItemsBean> list =
                            App.getDBcApplication().getCalenderNoteDetailData(userid, map.get(CLRepeatTable.repSourceDesc), false);
                    if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                        xcx_tv.setVisibility(View.VISIBLE);
                    }
                } else {
                    xcx_tv.setVisibility(View.GONE);
                }
            }
        } else if (mMap.get(ScheduleTable.schContent).length() > 2 && mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) {
            List<CalenderNoteBean.PageBean.ItemsBean> list =
                    App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);
            if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                xcx_tv.setVisibility(View.VISIBLE);
            } else {
                xcx_tv.setVisibility(View.GONE);
            }
        }  else {
            if (!"".equals(mMap.get(ScheduleTable.schRemark6))) {
                WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(mMap.get(ScheduleTable.schRemark6));
                if (bean != null && !bean.url.isEmpty()) {
                    xcx_tv.setVisibility(View.VISIBLE);
                } else {
                    xcx_tv.setVisibility(View.GONE);
                }
            }
        }

        if (isEnd != "1") {
            SpannableStringBuilder style = new SpannableStringBuilder((mMap.get(ScheduleTable.schContent).length() > 2 &&
                    mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                    mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                    mMap.get(ScheduleTable.schContent));
            String remark11 = mMap.get(ScheduleTable.schRemark11);
            if (remark11 == null || remark11.equals("")) {
                remark11 = "0";
            }
            int color = Integer.valueOf(remark11);
            if (color > 0) {
                style.setSpan(new BackgroundColorSpan(context.getResources().getColor(colorss[color])), 0, ((mMap.get(ScheduleTable.schContent).length() > 2 &&
                                mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                                mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                                mMap.get(ScheduleTable.schContent)).length(),
                        Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                if (color > 2) {
                    style.setSpan(new ForegroundColorSpan(Color.WHITE), 0,((mMap.get(ScheduleTable.schContent).length() > 2 &&
                                    mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) ?
                                    mMap.get(ScheduleTable.schContent).substring(2, mMap.get(ScheduleTable.schContent).length()) :
                                    mMap.get(ScheduleTable.schContent)).length(),
                            Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                }
                timeall_tv_content.setText(style);
            }

        }

        String TYPEINDEX = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.TYPEINDEX, "3");
        int newopeartType = Integer.valueOf(TYPEINDEX);
        if (newopeartType < 0) {
            timeall_after.setTextColor(Color.WHITE);
            timeall_tv_nongli.setTextColor(Color.WHITE);
            timeall_tv_week.setTextColor(Color.WHITE);
        }
        if (!sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.TYPEUID, "").equals("")) {
            swipeLayout.setScroll(false);
            select_cb.setClickable(false);
        } else {
            select_cb.setClickable(true);
        }

        if ("1" == mMap.get(ScheduleTable.schRemark1) && mMap.get(ScheduleTable.schRemark5) != null && !mMap.get(ScheduleTable.schRemark5).equals("")) {
                comename_tv.setText("To:"+mMap.get(ScheduleTable.schRemark5));
        }
    }
    private int colorss[] = {R.color.white,R.color.color_m_1,R.color.color_m_2,R.color.color_m_3,R.color.color_m_4,R.color.color_m_5};

    public void setNewState(List<LyNewNumBean.ListBean> listBean) {
        listBeanList.clear();
        listBeanList.addAll(listBean);
        notifyDataSetChanged();
    }

    private int measureTextViewHeight(String text, int textSize, int deviceWidth) {
        TextView textView = new TextView(context);
        textView.setText(text);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth,
                MeasureSpec.AT_MOST);
        int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0,
                MeasureSpec.UNSPECIFIED);
        textView.measure(widthMeasureSpec, heightMeasureSpec);
        return textView.getMeasuredHeight();
    }

    public void insertData(Map<String, String> map, int position) {
        notifyDataSetChanged();
    }

    public void setData(List<Map<String, String>> list) {
        this.mList = list;
        notifyDataSetChanged();
    }
    public String nums(int stylee, List<CalenderNoteBean.PageBean.ItemsBean> list) {
        int tick1 = 0;
        int tick2 = 0;
        for (CalenderNoteBean.PageBean.ItemsBean listBean : list) {
            if (listBean.endstate == 1) {
                tick1 += 1;
            }
            if (listBean.endstate == 2) {
                tick2 += 1;
            }
        }
        String title_new;
        if (stylee == 0) {
            if (list.size() == 0) {
                title_new = "0";
            } else {
                title_new = tick1 + "/" + list.size();
            }
        } else if (stylee == 4) {
            if (list.size() == 0) {
                title_new = "0";
            } else {
                title_new = tick1 + "/" + tick2 + "/" + list.size();
            }
        } else {
            title_new = list.size() + "";
        }

        return title_new;
    }
    public void removeItem(int position) {
        notifyDataSetChanged();
    }
    String color = "0";
    void setBGcolor(LinearLayout linearLayout, String type) {
        switch (type) {
            case "1":
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.repeat_bg_color1));
                break;
            case "2":
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.repeat_bg_color2));
                break;
            case "3":
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.repeat_bg_color3));
                break;
            case "4":
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.repeat_bg_color4));
                break;
            case "0":
                linearLayout.setBackground(context.getResources().getDrawable(R.drawable.repeat_bg_color1));
                break;
        }
    }
}
